package com.yc.wabc.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.wabc.pojo.SNSUserInfo;
import com.yc.wabc.pojo.WeixinOauth2Token;
import com.yc.wabc.utils.AdvancedUtil;
import com.yc.wabc.utils.ComUtil;
import com.yc.wabc.utils.TwoDimensionCode;

/**授权后的回调请求处理
 * 
 * @author Administrator
 *
 */
public class QrcodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1847238807216447030L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		String name = request.getParameter("name");
		String phone = request.getParameter("phone");
		String realPath=getServletContext().getRealPath("/");
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		
		
		if (!ComUtil.validParams(name,phone)) {
			String imgPath = realPath+"upload/"+phone+".png";
			String encoderContent = name+":"+phone;
			TwoDimensionCode handler = new TwoDimensionCode();
			handler.encoderQRCode(encoderContent, imgPath, "png");
			request.setAttribute("name", name);
			request.setAttribute("phone", phone);
			request.setAttribute("qrcode", basePath+"upload/"+phone+".png");
		}
		
		
		// 跳转到index.jsp
		request.getRequestDispatcher("qrcode.jsp").forward(request, response);
	}
}
